#include <iostream>
#include <vector>
using namespace std;

long unseq(vector<int> &num, int l, int r)
{
	if (l == r) {
		return 0;
	}

	if (l + 1 == r) {
		if(num[l] > num[r]){
                        swap(num[l], num[r]);
                        return 1;
                }
                return 0;
	}

	// if (l >= r) {
	// 	return 0;
	// }

	int mid = (l + r) / 2;
	int ln = mid - l + 1;
	int rn = r - mid;

	long lseq = unseq(num, l, mid);
	long rseq = unseq(num, mid + 1, r);

	vector<int> larr(ln + 1), rarr(rn + 1);
	for (int i = 0; i < ln; i++) {
		larr[i] = num[l + i];
	}
	larr[ln] = INT32_MAX;
	for (int i = 0; i < rn; i++) {
		rarr[i] = num[mid + 1 + i];
	}
	rarr[rn] = INT32_MAX;

	int ll = 0, rr = 0;
        long mseq = 0;
	for (int k = l; k <= r; k++) {
		if (larr[ll] <= rarr[rr]) {
			num[k] = larr[ll];
			ll++;
		} else {
			mseq += ln - ll;
			num[k] = rarr[rr];
			rr++;
		}
	}
	return lseq + rseq + mseq;
}

int main()
{
	int n = 0;
	cin >> n;

	vector<int> num(n, 0);
	for (int i = 0; i < n; i++) {
		cin >> num[i];
	}

	cout << unseq(num, 0, n - 1) << endl;
	return 0;
}
